import { createAction, ActionType, createReducer } from 'typesafe-actions';

export interface WordConditionDto {
    wordValue?: string;
    wordTagValue?: string;
    wordSourceId?: number;

    relation: boolean;
    source: boolean;
    subSource: boolean;
    tag: boolean;
}

export interface WordSearcherState {
    wordConditionDto: WordConditionDto;
}
export type WordSearcherActions = ActionType<typeof setState>;

/**
 * 更新searchpad的参数
 * @param param 
 */
export const setState = createAction('WORD_SEARCHER/SET_STATE')<WordSearcherState>();

const initialState: WordSearcherState = {
    wordConditionDto: {
        wordTagValue: '默认',
        wordValue: '',
        relation: false,
        source: false,
        subSource: false,
        tag: false,
    }
}

/**
 * 负责改变WordList的state的函数
 * @param state 
 * @param action 
 */
export const Reducer = createReducer<WordSearcherState, WordSearcherActions>(initialState)
    .handleAction(setState, (_, action) => action.payload)